﻿// ———————————————————————–
// <copyright file="IncidentEIDDStatusCode.cs" company="The MITRE Corporation">
//    Copyright (c) 2014 The MITRE Corporation. All rights reserved.
//    Licensed under the Apache License, Version 2.0 (the "License");
//    you may not use this file except in compliance with the License.
//    You may obtain a copy of the License at
//    http://www.apache.org/licenses/LICENSE-2.0
//    Unless required by applicable law or agreed to in writing, software
//    distributed under the License is distributed on an "AS IS" BASIS,
//    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//    See the License for the specific language governing permissions and
//    limitations under the License.
// </copyright>
// ———————————————————————–
/////////////////////////////////////////////////////////////////////////////////////////////////
// IncidentEIDDStatusCode.cs:
//
// Secondary statuses based off of EIDD.
//
// Project: IC.NET - CAD Library
// Author:  Jim Cronin - MITRE
/////////////////////////////////////////////////////////////////////////////////////////////////

// Copyright (c) 2014 The MITRE Corporation. All rights reserved.
//
// NOTICE
// This software was produced for the U. S. Government
// under Contract No. FA8721-09-C-0001, and is
// subject to the Rights in Noncommercial Computer Software
// and Noncommercial Computer Software Documentation Clause
// (DFARS) 252.227-7014 (JUN 1995)

using System;

namespace EDXLSharp.NIEMCADLib
{
  /// <summary>
  /// Secondary statuses based off of EIDD.
  /// </summary>
  public enum IncidentEIDDStatusCode
  {
    /// <summary>
    /// Incident cancelled
    /// </summary>
    Cancelled,

    /// <summary>
    /// Emergency responder has declared that a fire is under control
    /// </summary>
    FireUnderControl,

    /// <summary>
    /// The incident's location has changed
    /// </summary>
    NewLocation,

    /// <summary>
    /// The incident has been re-opened
    /// </summary>
    Reopened,

    /// <summary>
    /// The incident has had at least one emergency resource assigned to it
    /// </summary>
    ResourcesAssigned,

    /// <summary>
    /// At least one emergency resource is en route to the incident
    /// </summary>
    ResourcesEnroute,

    /// <summary>
    /// At least one emergency resource has arrived at teh location (on scene) of the incident
    /// </summary>
    ResourcesOnScene,

    /// <summary>
    /// Emergency responder has declared that the structure has been cleared.
    /// </summary>
    StructureCleared
  }

  public static class IncidentEIDDStatusCodeExtensions
  {
    /// <summary>
    /// Gets the text to be written to XML for the EventTypeCode
    /// </summary>
    /// <param name="code">The <see cref="EDXLSharp.NIEMCADLib.IncidentEIDDStatusCode"/> to convert to text</param>
    /// <returns>Text representation of the <see cref="EDXLSharp.NIEMCADLib.IncidentEIDDStatusCode"/></returns>
    public static string GetText(this IncidentEIDDStatusCode code)
    {
      switch (code)
      {
        case IncidentEIDDStatusCode.Cancelled:
          return "CANCELLED";
        case IncidentEIDDStatusCode.FireUnderControl:
          return "FIRE UNDER CONTROL";
        case IncidentEIDDStatusCode.NewLocation:
          return "NEW LOCATION";
        case IncidentEIDDStatusCode.Reopened:
          return "REOPENED";
        case IncidentEIDDStatusCode.ResourcesAssigned:
          return "RESOURCES ASSIGNED";
        case IncidentEIDDStatusCode.ResourcesEnroute:
          return "RESOURCES ENROUTE";
        case IncidentEIDDStatusCode.ResourcesOnScene:
          return "RESOURCES ON SCENE";
        case IncidentEIDDStatusCode.StructureCleared:
          return "STRUCTURE CLEARED";
        default:
          throw new ArgumentException("Not a known value for IncidentEIDDStatusCode: " + code.ToString());
      }
    }

    /// <summary>
    /// Converts a text value to an <see cref="EDXLSharp.NIEMCADLib.IncidentEIDDStatusCode"/>
    ///  - First checks for the XML text of each code
    ///  - Lastly just calls Enum.Parse
    /// </summary>
    /// <param name="value">String to parse</param>
    /// <returns><see cref="EDXLSharp.NIEMCADLib.IncidentEIDDStatusCode"/> described by value</returns>
    /// <exception cref="System.ArgumentNullException">Thrown if value is null</exception>
    /// <exception cref="System.ArgumentException">Thrown if value is empty or whitespace</exception>
    /// <exception cref="System.OverflowException">Thrown if value does not represent an <see cref="EDXLSharp.NIEMCADLib.IncidentEIDDStatusCode"/></exception>
    public static IncidentEIDDStatusCode GetCode(string text)
    {
      switch (text)
      {
        case "CANCELLED":
          return IncidentEIDDStatusCode.Cancelled;    
        case "FIRE UNDER CONTROL":
          return IncidentEIDDStatusCode.FireUnderControl;
        case "NEW LOCATION":
          return IncidentEIDDStatusCode.NewLocation;
        case "REOPENED":
          return IncidentEIDDStatusCode.Reopened;
        case "RESOURCES ASSIGNED":
          return IncidentEIDDStatusCode.ResourcesAssigned;
        case "RESOURCES ENROUTE":
          return IncidentEIDDStatusCode.ResourcesEnroute;
        case "RESOURCES ON SCENE":
          return IncidentEIDDStatusCode.ResourcesOnScene;
        case "STRUCTURE CLEARED":
          return IncidentEIDDStatusCode.StructureCleared;
        default:
          return (IncidentEIDDStatusCode)Enum.Parse(typeof(IncidentEIDDStatusCode), text);
      }
    }
  }
}
